package com.example.yunbiji0314.service.iml;

import com.example.yunbiji0314.dao.UserDao;
import com.example.yunbiji0314.pojo.User;
import com.example.yunbiji0314.service.UserService;
import com.example.yunbiji0314.util.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;
    @Override
    public int register(User user01) {
        // 页面传递过来的密码是明文  但是数据库要加密的 所以此时要把页面传递过来的密码进行加
        String miwen = Md5Util.encrypt(user01.getPassword());
        user01.setPassword(miwen);
        System.out.println("生成的密文："+miwen);
        // 把user中的密码改成密文
        return userDao.register(user01);
    }

    @Override
    public User login(User user) {
       return userDao.login(user.getUsername());
    }

    @Override
    public int saveupload(User user) {
        return userDao.saveupload(user);
    }

    @Override
    public int savepassword(User user) {
        String miwen = Md5Util.encrypt(user.getPassword());
        user.setPassword(miwen);
        return userDao.savepassword(user);
    }

    @Override
    public int saveinfo(User user) {
        return userDao.saveinfo(user);
    }

}
